package pogvue.datamodel;

import pogvue.util.Format;

import java.io.PrintStream;

public final class TFMatrix {

    public final double[][] value;
    public final int rows;
    public final int cols;
    public Pwm pwm;

    String name;
    String id;
    String acc;
    String desc;
    String cons;

    public TFMatrix(double[][] value, int rows, int cols) {
	this.rows = rows;
	this.cols = cols;
	this.value = value;

	name = "";
	id   = "";
	acc  = "";
	desc = "";
	cons = "";

	makePwm();
    }
    public Pwm getPwm() {
       return pwm;
    }
  public double getInformationContent() {
    if (pwm != null) {
      return pwm.getInformationContent();
    } 
    return 0;
  }
    public void makePwm() {
        double[] mat = new double[rows*cols];
        //System.out.println("Matrix " + rows + " " + cols);

	for (int i = 0; i < rows; i++) {
	    int tot = 0;
            for (int j = 0; j < cols; j++) {
	        mat[i*4+j] = value[i][j];
		tot += value[i][j];
             }
	     if (tot > 0) {
            for (int j = 0; j < cols; j++) {
	        mat[i*4+j] /= tot;
            }
	    }
         }	

	 pwm = new Pwm(mat,name);

	 //System.out.print("Logo ");
	 //Pwm.printLogo(pwm.getPwm());	
	 //System.out.println();
     }
    public void print(PrintStream ps) {
	
	for (int i = 0; i < rows; i++) {
	    for (int j = 0; j < cols; j++) {
		Format.print(ps,"%8.2f",value[i][j]);
	    }
	    ps.println();
	}
    }
    public double[][] getValues() {
	return value;
    }
    public void setAcc(String acc) {
	this.acc = acc;
    }
    public String getAcc() {
	return acc;
    }
    public void setName(String name) {
	this.name = name;
    }
    public String getName() {
	return name;
    }
    public void setId(String id) {
	this.id = id;
    }
    public String getId() {
	return id;
    }
    public void setDesc(String desc) {
	this.desc = desc;
    }
    public String getDesc() {
	return desc;
    }
    public int getRows() {
	return rows;
    }
    public void setConsensus(String cons) {
	this.cons = cons;
    }
    public String getConsensus() {
	return cons;
    }
}







